home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / updates / update24.zoo / lib / stricmp.c < prev    next >
C/C++ Source or Header  |  1992-08-14  |  1KB  |  46 lines

  1. /* derived from strcmp from Henry Spencer's stringlib */
  2. /* modified by ERS */
  3. /* i-changes by Alexander Lehmann */
  4.  
  5. #include <string.h>
  6. #include <ctype.h>
  7.  
  8. /*
  9.  * stricmp - compare string s1 to s2 without case sensitivity
  10.  *           result is equivalent to strcmp(strupr(s1),s2)),
  11.  *           but doesn't change anything
  12.  */
  13.  
  14. asm(".stabs \"_strcmpi\",5,0,0,_stricmp"); /* dept of clean tricks */
  15.  
  16. int                             /* <0 for <, 0 for ==, >0 for > */
  17. stricmp(scan1, scan2)
  18. register const char *scan1;
  19. register const char *scan2;
  20. {
  21.         register char c1, c2;
  22.  
  23.         if (!scan1)
  24.                 return scan2 ? -1 : 0;
  25.         if (!scan2) return 1;
  26.  
  27.         do {
  28.                 c1 = *scan1++; c1=toupper(c1);
  29.                 c2 = *scan2++; c2=toupper(c2);
  30.         } while (c1 && c1 == c2);
  31.  
  32.         /*
  33.          * The following case analysis is necessary so that characters
  34.          * which look negative collate low against normal characters but
  35.          * high against the end-of-string NUL.
  36.          */
  37.         if (c1 == c2)
  38.                 return(0);
  39.         else if (c1 == '\0')
  40.                 return(-1);
  41.         else if (c2 == '\0')
  42.                 return(1);
  43.         else
  44.                 return(c1 - c2);
  45. }
  46.